// import { useRouter } from "vue-router";
// const router = useRouter();

// import { useDebounceFn, useThrottleFn } from "@vueuse/core";
// import http from "@/utils/system/request";
import clipboard3 from "vue-clipboard3";
// 解构方法
const { toClipboard } = clipboard3();

// @ts-ignore
import router from "@/router/index";
import { ElMessage, ElLoading } from "element-plus";
// const useDebounce = useDebounceFn(() => "response", 500);
// const useThrottle = useThrottleFn(() => "response", 1000);

// import setPageTitle from "@/utils/set-page-title";
const gotoBack = () => {
  router.back();
};
const onCopyFn = text => {
  try {
    toClipboard(text);
    console.log("复制成功");
  } catch (err) {
    console.error(err);
    console.log("复制失败，请手动复制");
  }
};
const gotoPath = path => {
  console.log(path);
  if (!path) return console.log("暂时还没有页面");
  router.push(path);
};
const JumpLink = path => {
  if (!path) return console.log("暂时还没有页面");
  window.open(path);
};

// const JumpServiceLink = (path = "") => {
//   window.open(
//     "https://api.whatsapp.com/send/?phone=85262891140&text&type=phone_number&app_absent=0",
//   );
// };
// // pub-use.ts
// // 获取assets静态资源
// const getAssetsFile = (url) => {
//   // console.log(new URL(`../icons/${url}`, import.meta.url).href);
//   // debugger;
//   // return new URL(`../${url}`, import.meta.url).href;
// };

const afterRead = file => {
  // showLoadingToast("上传中");
  console.log(file, "1222222");
  const files = file.file;
  const formData = new FormData();
  formData.append("name", files.name);
  formData.append("fileData", files);
  console.log(formData, "forms");
  // http
  //   .post(`h5/upload/image`, { fileData: formData })
  //   .then(({ code, data }: any) => {
  //     console.log(code, data);
  //   });
};
const showErrorToast = title => {
  ElMessage.error(title);
};
const showSuccessToast = title => {
  ElMessage.success(title);
};
const showWarningToast = title => {
  ElMessage.warning(title);
};
var loadingInstance = null;
const showLoading = title => {
  loadingInstance = ElLoading.service({
    lock: true,
    text: title,
    background: "rgba(0, 0, 0, 0.2)"
  });
  console.log("加载中");
};
const closeLoading = () => {
  loadingInstance.close();
};

export {
  gotoBack,
  gotoPath,
  afterRead,
  // getAssetsFile,
  // useDebounce,
  // useThrottle,
  // setPageTitle,
  JumpLink,
  // JumpServiceLink,
  onCopyFn,
  // useThrottleFn,
  showErrorToast,
  showSuccessToast,
  showWarningToast,
  closeLoading,
  showLoading
};
